package GameLogic;

public class EffectSplatter extends Effect{
	private float threshold = 3.0f;
	private double velFactorX;
	private double velFactorY;

	EffectSplatter(EntityCoordinate source)
	{
		cDeath(source);
	}
	
	EffectSplatter()
	{
		EntityCoordinate tCoord = new EntityCoordinate();
		tCoord.posX = 0;
		tCoord.posY = 0;
		cDeath(tCoord);
	}

	private void cDeath(EntityCoordinate body)
	{
		model = new EntityModel();
		model.texture_path = "res/splat.png";
		
		 model.frames=1;                            //model does not have any frames
	        model.texture_coordinates=new float[] {0.0f, 0.0f,      //quad vertices; NOTICE: if you start with 0 as bottom left vertex
	                                     0.0f, 1.0f,       // it will spin around this vertex (rotate is performed on 0,0)
	                                     1.0f, 1.0f,
	                                     1.0f, 0.0f};
	        model.vertex_colour = new float[] {0.0f, 0.0f, 0.0f, 1.0f,  //RGBA, each vertex of quad
	                                        0.0f, 0.0f, 0.0f, 1.0f,
	                                        0.0f, 0.0f, 0.0f, 1.0f,
	                                        0.0f, 0.0f, 0.0f, 1.0f};
	         model.vertices = new float[] {-0.125f, -0.125f,      //quad vertices; NOTICE: if you start with 0 as bottom left vertex
	                                     0.125f, -0.125f,       // it will spin around this vertex (rotate is performed on 0,0)
	                                     0.125f, 0.125f,
	                                     -0.125f, 0.125f};
	     eCoord.posX = body.posX;
	     eCoord.posY = body.posY;
	     eCoord.scaleX = 0.05f;
	     eCoord.scaleY = 0.05f;
	     velFactorX = 2*(Math.random()-0.5);
	     //velFactorY = Math.abs(2*(Math.random()-0.5));
	     velFactorY = Math.random();
	     threshold = 2.0f;
	}
	
	public void tick()
	{
		super.tick();
		updateMovementByPath();
		//System.out.println("Dead body exists");
	}
	public boolean hasExpired()
	{
		return timeExisted > threshold;
	}
	@Override
	void updateMovementByPath() {
		eCoord.posX -= 0.0085f*velFactorX;
		eCoord.posY -= Math.pow(timeExisted, 2.0f)*velFactorY;
	}
}
